#region License

//
// Author: Javier Lozano <javier@lozanotek.com>
// Copyright (c) 2009-2010, lozanotek, inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#endregion

namespace Okonau.Mvc.ViewModels {
    using System.Collections.Generic;
    using AutoMapper;
    using Domain;

    /// <summary>
    /// Extensions for <see cref="Task"/> and related view models.
    /// </summary>
    public static class TaskModelExtensions {
        /// <summary>
        /// Static constructor
        /// </summary>
        static TaskModelExtensions() {
            Mapper.CreateMap<Task, TaskViewModel>();
        }

        /// <summary>
        /// Converts the list of <see cref="Task"/> into list of <see cref="TaskViewModel"/>.
        /// </summary>
        /// <param name="tasks"></param>
        /// <returns></returns>
        public static IList<TaskViewModel> ToViewModel(this IEnumerable<Task> tasks) {
            var list = new List<TaskViewModel>();
            foreach (Task task in tasks) {
                list.Add(task.ToViewModel());
            }

            return list;
        }

        /// <summary>
        /// Converst a <see cref="Task"/> into a <see cref="TaskViewModel"/>.
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public static TaskViewModel ToViewModel(this Task task) {
            return Mapper.Map<Task, TaskViewModel>(task);
        }
    }
}
